#ifndef __APP_DEF_H__
#define __APP_DEF_H__

#include "udf_def.h"
#include "radar_user_def.h"

/* 版本号 */
#if SDK_VERSION < SDK_VERSION_GENE(3,0)
#define FW_VERSION_CAT(a,b) a##_210.21.3.##b
#else
#define FW_VERSION_CAT(a,b) a##_300.21.3.##b
#endif
#define MACRO_STR(x) #x
#define TO_STR(x) MACRO_STR(x)

//#define VCO_OUTPUT_ENABLE // gpio0.4 输出vco信号以调试

#if 1 /* 应用配置 */

//#define UART_PARAM_CFG_ENABLE

#define IIC_OUTPUT_ENABLE

//#define GPIO_OUTPUT_ENABLE      // GPIO输出配置

#if !defined(BD_GPIO_OUTPUT_PIN) || !defined(BD_GPIO_OUTPUT_PIN_SET)
#if defined(GPIO_OUTPUT_ENABLE)
#undef GPIO_OUTPUT_ENABLE
#endif
#endif

#if defined(GPIO_OUTPUT_ENABLE)
#define GPIO_OUTPUT_MODE    (0) // 0-OD 1-PP
#define GPIO_OUTPUT_ACTIVE  (0) // 0-low 1-high
#define GPIO_OUTPUT_PULL    (0) // 0-下拉 1-上拉
#define GPIO_OUTPUT_ID      (BD_GPIO_OUTPUT_PIN) // gpio0.x
#define GPIO_OUTPUT_SET     BD_GPIO_OUTPUT_PIN_SET
#endif

#if defined(UART_PARAM_CFG_ENABLE)
#define UART_RECV_ENABLE    // 串口接收
#endif

#define APP_INDEPENDENT     // 独立应用 不开启此项则为辅助应用(其它主应用无目标则切换到本应用)
#define LOWPOWER_ENABLE     // 低功耗开关
#define POINTRST_ENABLE     // 点云开关
#ifdef  POINTRST_ENABLE     // 点云输出接口
#define POINTRST_INTERFACE  (0) // 0 uart  1 spi
#endif

#define APP_HAS_MULTI_UDF  // 多udf

#if (TEST_MODE > 0 )
#if defined(UART_RECV_ENABLE)
#undef UART_RECV_ENABLE
#endif

#if defined (UART_PARAM_CFG_ENABLE)
#undef UART_PARAM_CFG_ENABLE
#endif

#endif

// 待机功耗测试，关闭GPIO输出功能
#if (TEST_MODE == 201) || (TEST_MODE == 202) || (TEST_MODE == 203) || (TEST_MODE == 300) || (TEST_MODE == 400)
#ifdef GPIO_OUTPUT_ENABLE
#undef GPIO_OUTPUT_ENABLE
#endif
#endif

#if (TEST_MODE == 204)

#if defined(POINTRST_ENABLE)
#undef POINTRST_ENABLE
#endif

#endif

#endif

#if defined(APP_HAS_MULTI_UDF) && (ENABLE_UDF13>0)
struct task_info{
	uint32_t bk1;
	uint16_t bk2;
	uint8_t bk3; 
};
#endif

// 必须保证UDF_global结构体类型有定义 
// magic_flag_A、magic_flag_B为构建需要初始值不可修改，且位置必须位于结构体最后。
typedef struct{
	uint32_t  frame_fifo_index;
	uint32_t  has_target_cnt_lck;

	#if defined(APP_HAS_MULTI_UDF) && (ENABLE_UDF13>0) && (SDK_VERSION < SDK_VERSION_GENE(3,0))
	struct task_info task_info;
	#endif

	#if defined(UART_RECV_ENABLE)
	uint32_t uart_wait_cnt_ms;
	#endif
	
	#if defined(UART_PARAM_CFG_ENABLE)
	uint16_t param_cfg_status;
	uint16_t config_mode_exit;
	#endif

	uint8_t draw_id;


	uint8_t i2c_reg00;
	uint8_t i2c_reg10;
	uint8_t i2c_reg11;
	uint8_t i2c_reg12;
	uint8_t i2c_reg13; 
	uint8_t i2c_reg31;
	uint8_t i2c_reg32;
	uint8_t i2c_reg3e;
	uint8_t i2c_reg3f;	
	uint8_t i2c_reg41;
	uint8_t i2c_reg42;
	uint8_t i2c_reg43;
    uint8_t i2c_reg44;
    uint8_t i2c_reg45;
	uint8_t i2c_reg4e;
	uint8_t i2c_reg4f;
	uint8_t i2c_reg5c;
	uint8_t i2c_reg61;
	uint8_t i2c_reg67;
	uint8_t i2c_reg68;
	uint8_t i2c_regaa;
	uint8_t i2c_regbb[256];

	uint8_t binpage_cnt;

	uint8_t start_f;
	uint8_t stop_f;
	uint8_t state;
	uint32_t cnt;
	uint8_t rtc_f;	
//  uint32_t range_Set_outone;
//  uint32_t range_Set_outtwo;
//  uint32_t two_noflag;
//  uint32_t last_index_cnt;
//  uint32_t cnt_flag;
//  uint32_t one_noflag;
//  uint32_t one_cnt_flag;
  
  uint8_t version[4];
  
  	uint32_t magic_flag_A;
	uint32_t magic_flag_B;
}sUDF_global_t;

#endif
